package com.lujianfei.productprice.ui.addShop;

import android.os.Bundle;
import android.widget.EditText;

import com.lujianfei.productprice.R;
import com.lujianfei.productprice.base.BaseActivity;
import com.lujianfei.productprice.ui.main.ShopEntity;

public class AddShopActivity extends BaseActivity implements AddShopContract.View {

    AddShopContract.Presenter presenter;

    EditText editShopName;
    EditText editShopRemark;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_shop);
        setTitleMiddleText(-1 == getId()?"添加店铺":"编辑店铺");
        showTitleRightImage();
        setTitleRightImage(R.drawable.ic_ok);
        editShopName = findViewById(R.id.editShopName);
        editShopRemark = findViewById(R.id.editShopRemark);
        presenter = new AddShopPresenter(this);
        presenter.loadData();
    }

    @Override
    public void onTitleRightImageClick() {
        super.onTitleRightImageClick();
        presenter.save();
        finish();
    }

    @Override
    protected int getTitleBarResId() {
        return R.id.custom_titlebar;
    }

    @Override
    public long getId() {
        return getIntent().getLongExtra("id",-1);
    }

    @Override
    public void setData(ShopEntity shopEntity) {
        if (null==shopEntity){
            return;
        }
        editShopName.setText(shopEntity.getShopName());
        editShopRemark.setText(shopEntity.getRemark());
    }

    @Override
    public String getShopName() {
        return editShopName.getText().toString();
    }

    @Override
    public String getShopRemark() {
        return editShopRemark.getText().toString();
    }
}
